/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var channel_share_timeout = 10000;

function channel_share(){       
    if($('#acx_item_id').val() == ''){
        alert("Hãy lưu  thông tin Album trước khi share");
        return false;
    }
    $(".progressbar").progressbar( "option", "value", 0 );            
    //    $("#channel_publish").dialog("open");
                                
    //Get group share
    $.ajax({
        timeout: channel_share_timeout,
        type: "GET",
        url: $('#base_url').val() + 'sharing/get_group?type='+ $("#permission").val(),                                   
        beforeSend: (function(){
                                            
            }),
        success: (function(msg) {                                             
            insert_group_list(jQuery.parseJSON(msg.data))                                          
        }),
        complete: (function() {

            }),
        dataType: "json"
    });
                                
    return false;
};

                            
function insert_group_list(jsonArray){   
    console.log(jsonArray);
    if(jsonArray != ''){
        var i;
        var url = $('#base_url').val();             
        console.log(jsonArray.length);            
        if(jsonArray.length == 0){
            data += '<tr>';
            data += '<td colspan="5">Không có group</td>';
            data += '</tr>';
            $("#imageloadmore").hide();
        }                                   
        else{
            data = '';
            $.each( jsonArray, function( state, group) {                                                                                                                                                            
                console.log(group);                                           
                data += '<input type="checkbox" name="group_share[]" value="'+ group.group_id +'::'+ group.group_name +'" />';                                                
                                                
                data += group.group_name + "</br>";                                                                                                                                                                                           
            });
            $("#list_group_share").html(data);                   
        }
    }
}


/**
* photo_up
*
*/
function photo_up(el)
{
    tr = el.parent().parent();
    up = tr.index();
    if(up < 1)
        return false;
    $('tr').eq(up).before(tr.outerHTML());
    tr.remove();
    auto_rank();
    return false;
}

/**
* photo_down
*
*/
function photo_down(el)
{
    tr = el.parent().parent();
    down = tr.index() + 2;
    if(down > $('#table_album_photos tr:last').index())
        return false;
    $('tr').eq(down).after(tr.outerHTML());
    tr.remove();
    auto_rank();
    return false;
}